Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit debug logs to 4096 bytes on vercel to avoid errors #1598

Merged
merged 4 commits into from
Aug 15, 2023

Conversation

jescalan
Copy link
Contributor

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Packages affected

  • @clerk/clerk-js
  • @clerk/clerk-react
  • @clerk/nextjs
  • @clerk/remix
  • @clerk/types
  • @clerk/themes
  • @clerk/localizations
  • @clerk/clerk-expo
  • @clerk/backend
  • @clerk/clerk-sdk-node
  • @clerk/shared
  • @clerk/fastify
  • @clerk/chrome-extension
  • gatsby-plugin-clerk
  • build/tooling/chore

Description

  • npm test runs as expected.
  • npm run build runs as expected.

When deployed to Vercel, logs cannot exceed 4096 bytes, or no logs are displayed at all and the user gets an error instead. This PR truncates debug logs to 4096 bytes to ensure that they display correctly on Vercel.

Fixes JS-608

@changeset-bot
Copy link

changeset-bot bot commented Aug 15, 2023

🦋 Changeset detected

Latest commit: c092747

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

@jit-ci jit-ci bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Great news! Jit hasn't found any security issues in your PR. Good Job! 🏆

@@ -1,5 +1,7 @@
// TODO: Replace with a more sophisticated logging solution

import truncate from 'truncate-utf8-bytes';
Copy link
Member

@BRKalow BRKalow Aug 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we intentionally try to mitigate usage of 3p dependencies in our packages. We can inline this pretty easily using TextEncoder and TextDecoder:

function truncate(str: string, maxLength: number) {
	const encoder = new TextEncoder();
	const decoder = new TextDecoder('utf-8');

	const encodedString = encoder.encode(str);
	const truncatedString = encodedString.slice(0, maxLength);

	// return the truncated string, removing any replacement characters that result from partially truncated characters
	return decoder.decode(truncatedString).replace(/\uFFFD/g, '');
}

(ref)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to shift over to this, but I was reluctant to do so initially since it doesn't handle multi-byte characters, where the library I included does, and is hardly any more code overall. We could copy-paste the 3p library code too, but that seems a little silly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jescalan The above sort of handles the multi-byte characters by stripping out the leftovers if they get split. I see what you're saying, but let's inline for now and we can revisit the stance on dependencies as a team. The fact that our deps list is so short feels deliberate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷‍♂️ done!

@jescalan jescalan requested a review from BRKalow August 15, 2023 20:00
Copy link
Member

@BRKalow BRKalow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I think we need a patch changeset here and then it's good to go. Nice work

@jescalan jescalan merged commit ee9e2d9 into main Aug 15, 2023
8 checks passed
@jescalan jescalan deleted the je.vercel-log-limit branch August 15, 2023 20:30
@clerk-cookie clerk-cookie mentioned this pull request Aug 15, 2023
@clerk-cookie
Copy link
Collaborator

This PR has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@clerk clerk locked as resolved and limited conversation to collaborators Aug 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants